<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <HomeCategory />
        <!-- banner轮播图 -->
        <HomeBanner />

        <HomePannel title="新鲜好物" subTitle="新鲜好物 快来抢购">
          <template #right>
            <!-- 查看更多 -->
            <XtxMore></XtxMore>
          </template>
          <!-- 主体区域 好货图片 -->
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in goodlist" :key="item.id">
                <RouterLink :to="`/goods/${item.id}`">
                <!-- 使用自定义指令图片懒加载 -->
                  <img v-img-lazy="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePannel>
        <HomePannel title="人气推荐" subTitle="人气推荐 不容错过">
          <template #right>
            <!-- 查看更多 -->
            <XtxMore></XtxMore>
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in hotList" :key="item.id">
                <RouterLink to="/">
                  <img v-img-lazy="item.picture" alt="" />
                  <p class="name">{{ item.title }}</p>
                  <p class="name">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePannel>
        <!-- 品牌模块 -->
        <HomePannel title="热门品牌" subTitle="热门品牌 快来抢购">
          <template #right>
            <!-- 查看更多 -->
            <XtxMore></XtxMore>
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in brandList" :key="item.id">
                <RouterLink to="/">
                  <img
                  v-img-lazy="item.picture"
                  :src="item.picture"
                  alt=""
                  class="brand-img"
                  />

                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePannel>
      </div>
    </div>
  </div>
</template>

<script>
import HomeCategory from './components/home-category'
import HomeBanner from './components/home-banner'
import HomePannel from './components/home-pannel'
import { ref } from 'vue'
import { findNewAPI, findHotAPI, findHotBrandAPI } from '@/api/home'
export default {
  name: 'PageHome',
  components: {
    HomeCategory,
    HomeBanner,
    HomePannel
  },
  setup () {
    // 获取好物列表
    const goodlist = ref([])
    async function getListFn () {
      const res = await findNewAPI()
      goodlist.value = res.result
    }
    getListFn()

    // 获取人气推荐列表
    const hotList = ref([])
    async function getHotListFn () {
      const res = await findHotAPI()
      hotList.value = res.result
    }
    getHotListFn()

    // 获取热门品牌列表
    const brandList = ref([])
    async function getbrandListFn () {
      const res = await findHotBrandAPI()
      brandList.value = res.result
    }
    getbrandListFn()

    return {
      goodlist,
      hotList,
      brandList
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
// 自己加一个热门品牌的图片样式
    .brand-img {
      width: 228px;
      height: 290px;
      margin-left: 10px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}

</style>
